package com.major.hash;

public class EmpLinked {
    private Emp head;

    // 添加
    public void add(Emp emp) {
        if (head == null) {
            head = emp;
            return;
        }
        Emp temp = head;
        // 找到最后
        while (temp.getNext() != null) {
            temp = temp.getNext();
        }
        temp.setNext(emp);
    }

    // 遍历
    public void list(int i) {
        if (head == null) {
            System.out.println("第" + (i + 1) + "条链表信息为空");
            return;
        }
        System.out.println("第" + (i + 1) + "条链表信息为：");
        Emp temp = head;

        while (true){
            System.out.println(temp.toString());
            if (temp.getNext() == null){
                break;
            }
            temp = temp.getNext();
        }
//        System.out.println(temp.toString());
//        while (temp.getNext() != null){
//            System.out.println(temp.toString());
//            temp = temp.getNext();
//        }
    }

    public Emp findEmpById(int id) {
        if (head == null){
            //System.out.println("链表为空");
            return null;
        }
        Emp temp = head;
        while (temp.getId() != id){
            temp = temp.getNext();
        }
        if (temp.getId() == id){
            return temp;
        }
        return null;
    }
}